#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
using namespace std;
int main1006()
{
	int p,e,i,d;
	int idx = 0;
	while(cin >>p >> e >> i >> d)
	{
		if (p == -1 && e == -1 && i == -1 && d == -1)
		{
			break;
		}
		idx++;
		int ans;
		int r1,r2,r3;
		r1 = p % 23;

		//r2 = (17 * (r1 - e)) % 28;
		int _r2 = (((r1 - e) << 4) + (r1 - e));
		_r2 = _r2 % 28;
		//r3 = (2 * (i - r1 - 23 * r2)) % 33;
		int _r3 = (i - r1 - 23 * _r2) << 1;
		_r3 = _r3 % 33;
		//ans = r1 + 23 * (r2 + 28 * (r3));
		ans = r1 + 23 * _r2 + 644 * _r3;

		//cout << ans << " " << _ans << endl;
		ans -= d;
		if (ans <= 0)
		{
			ans += 21252;
		}



		cout << "Case " << idx <<": the next triple peak occurs in " << ans <<" days."<<endl;

	}
	return 0;
}